
#ifndef UTILS_H
#define UTILS_H

#include <stdio.h>
#include "storage.h"

static const char CONFIG_COMMENT_CHAR = '#';

#define MAX_CMD_LEN (1024 * 8)

#define LOG(x)  {printf x; fflush(stdout);}

#ifdef NDEBUG
#define DBG(x)  {}
#else
#define DBG(x)  {printf x; fflush(stdout);}
#endif

struct config_params {
        char server_host[MAX_HOST_LEN];

        int server_port;

        char username[MAX_USERNAME_LEN];

        char password[MAX_ENC_PASSWORD_LEN];

//      char data_directory[MAX_PATH_LEN];
};

static inline void die(char *msg, int code)
{
        printf("%s\n", msg);
        exit(code);
}

FILE* serverFile;	//FilePTRs
FILE* clientFile;


void closeC(int logVar);	//Close files

void closeS(int logVarS);

int sendall(const int sock, const char *buf, const size_t len);

int recvline(const int sock, char *buf, const size_t buflen);

int read_config(const char *config_file, struct config_params *params);

void logger(FILE *file, char *message, int doLogging);	//Logger

#define DEFAULT_CRYPT_SALT "xx"

char *generate_encrypted_password(const char *passwd, const char *salt);

#endif

